<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lanqilu.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":true},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#395ca3","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":true,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Spring中常用的设计模式">
<meta property="og:type" content="article">
<meta property="og:title" content="设计模式">
<meta property="og:url" content="https://lanqilu.github.io/2020/07/30/Spring/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/index.html">
<meta property="og:site_name" content="Halo">
<meta property="og:description" content="Spring中常用的设计模式">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-30T04:28:27.000Z">
<meta property="article:modified_time" content="2020-08-09T00:12:00.687Z">
<meta property="article:author" content="Lanqilu">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Spring">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://lanqilu.github.io/2020/07/30/Spring/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>设计模式 | Halo</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-161500949-1"></script>
    <script data-pjax>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-161500949-1');
      }
    </script>


  <script data-pjax>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?256151d1651e9d73ec980b2fc69de8f6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Halo</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">39</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">85</span></a>

  </li>
        <li class="menu-item menu-item-python">

    <a href="/categories/Python/" rel="section"><i class="fa fa-fw fa-code"></i>Python</a>

  </li>
        <li class="menu-item menu-item-java">

    <a href="/categories/Java/" rel="section"><i class="fa fa-fw fa-code"></i>Java</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lanqilu.github.io/2020/07/30/Spring/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="http://img.whl123456.top/image/avatar.jpg">
      <meta itemprop="name" content="Lanqilu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Halo">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          设计模式
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-30 12:28:27" itemprop="dateCreated datePublished" datetime="2020-07-30T12:28:27+08:00">2020-07-30</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-09 08:12:00" itemprop="dateModified" datetime="2020-08-09T08:12:00+08:00">2020-08-09</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <div class="note info no-icon">
            <p>Spring中常用的设计模式</p>
          </div>

<a id="more"></a>

<hr>
<h2 id="面向对象的七大设计原则"><a href="#面向对象的七大设计原则" class="headerlink" title="面向对象的七大设计原则"></a>面向对象的七大设计原则</h2><ul>
<li>开闭原则：对扩展开放，对修改关闭。</li>
<li>里氏替换原则：继承必须确保超类所拥有的性质在子类中仍然成立。</li>
<li>依赖倒置原则：要面向接口编程，不要面向实现编程。</li>
<li>单一职责原则：控制类的粒度大小、将对象解耦、提高其内聚性。</li>
<li>接口隔离原则：要为各个类建立它们需要的专用接口。</li>
<li>迪米特法则：只与你的直接朋友交谈，不跟”陌生人”说话。</li>
<li>合成复用原则：尽量先使用组合或者聚合等关联关系来实现，其次才考虑使用继承关系来实现。</li>
</ul>
<h3 id="开闭原则"><a href="#开闭原则" class="headerlink" title="开闭原则"></a>开闭原则</h3><p>开闭原则（OCP）是指一个软件实体（如类、模块和函数）应该对扩展开放，对修改关闭。</p>
<p>开闭原则是面向对象设计中最基础的设计原则。例如版本更新，我们尽可能不修改源代码，但是可以增加新功能。</p>
<p>开闭原则的核心思想就是面向抽象编程</p>
<h3 id="依赖倒置原则"><a href="#依赖倒置原则" class="headerlink" title="依赖倒置原则"></a>依赖倒置原则</h3><p>依赖导致原则（DIP）是指设计代码结构时，高层模块不应该依赖低层模块，两者都应该依赖其抽象。抽象不应该依赖细节，细节应该依赖抽象。通过依赖倒置，可以减少类与类之间的耦合性，提高系统的稳定性，提高代码的可读性和可维护性，并能够降低修改程序所造成的风险。</p>
<h3 id="单一职责原则"><a href="#单一职责原则" class="headerlink" title="单一职责原则"></a>单一职责原则</h3><p>单一职责原则（SRP）是指不要存在多于一个导致类变更的原因。类、方法、接口单一</p>
<h3 id="接口隔离原则"><a href="#接口隔离原则" class="headerlink" title="接口隔离原则"></a>接口隔离原则</h3><p>接口隔离原则（ISP）是指用多个专门的接口，而不使用单一的总接口，客户端不应该依赖他不需要的接口。指导接口的设计：</p>
<ul>
<li>一个类对另一个类的依赖应该建立在最小的接口之上</li>
<li>建立单一接口，不要建立庞大臃肿的接口</li>
<li>尽量细化接口，接口中的方法尽量少（适度）</li>
</ul>
<h3 id="迪米特原则"><a href="#迪米特原则" class="headerlink" title="迪米特原则"></a>迪米特原则</h3><p>迪米特原则（LoD）是指一个对象应该对其他对象保持最少的了解，又叫最少知道原则（LKP），尽量降低类与类之间的耦合度。迪米特原则强调：只和朋友交流，不和陌生人说话。出现在成员变量、方法的输入、输出参数中的类都可以称为成员朋友类，而出现在方法体内部的类不属于朋友类。</p>
<h3 id="里氏替换原则"><a href="#里氏替换原则" class="headerlink" title="里氏替换原则"></a>里氏替换原则</h3><h3 id="合成复用原则"><a href="#合成复用原则" class="headerlink" title="合成复用原则"></a>合成复用原则</h3><h2 id="Spring中常用的设计模式"><a href="#Spring中常用的设计模式" class="headerlink" title="Spring中常用的设计模式"></a>Spring中常用的设计模式</h2><p>设计模式的本质是面向对象设计原则的实际运用，是对类的封装性、继承性和多态性以及类的关联关系和组合关系的充分理解。</p>
<p>正确使用设计模式具有以下优点：</p>
<ul>
<li>可以提高程序员的思维能力、编程能力和设计能力。</li>
<li>使程序设计更加标准化、 代码编制更加工程化，使软件开发效率大大提高,从而缩短软件的开发周期</li>
<li>使设计的代码可重用性高、可读性强、可靠性高、灵活性好、可维护性强。</li>
</ul>
<h3 id="工厂模式"><a href="#工厂模式" class="headerlink" title="工厂模式"></a>工厂模式</h3><p>在大部分的情况下，我们都是以<code>new</code>关键字来创建对象的。举个例子，现实中车子的种类可能很多，有大巴车、轿车、救护车、越野车、卡车等，每个种类下面还有具体的型号，一个工厂生产如此多的车会难以管理，所以往往还需要进一步拆分为各个分工厂：大巴车、轿车等分工厂。但是客户不需要知道工厂是如何拆分的，他只会告诉客服需要什么车，客服会根据客户的需要找到对应的工厂去生产车。对客户而言，车厂只是一个抽象概念，他只是大概知道有这样的一个工厂能满足他的需要。</p>
<h4 id="普通工厂（Simple-Factory）模式"><a href="#普通工厂（Simple-Factory）模式" class="headerlink" title="普通工厂（Simple Factory）模式"></a>普通工厂（Simple Factory）模式</h4><p>在程序中往往也是如此，例如，有个 PRoduct的产品接口，它下面有5个实现类Product1、 Product2、 Product.3、 Product4、 Product5。它们属于一个大类，可以通过一个工厂去管理它们的生成，但是由于类型不同，所以初始化有所不同。为了方便使用产品工厂（ Product Factory）类来创建这些产品的对象，用户可以通过产品号来确定需要哪种产品。</p>
<p>不同的用户可能不知道彼此订了什么类型的产品，只知道对方订了产品，满足 PRoduct接口的定义，这样就有了 ProductFactory类的伪代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ProductFactory</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> IProduct createProduct（String productNo）&#123;</span><br><span class="line">        <span class="keyword">switch</span> (productIo)&#123;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"1"</span>:<span class="keyword">return</span> <span class="keyword">new</span> Product1(xxxx);</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"2"</span>:<span class="keyword">return</span> <span class="keyword">new</span> Product2(xxxx);</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"3"</span>:<span class="keyword">return</span> <span class="keyword">new</span> Product3(xxxx); </span><br><span class="line">            <span class="keyword">case</span> <span class="string">"4"</span>:<span class="keyword">return</span> <span class="keyword">new</span> Product4(xxxx);</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"5"</span>:<span class="keyword">return</span> <span class="keyword">new</span> Product5(xxxx);</span><br><span class="line">            <span class="keyword">default</span>: <span class="keyword">throw</span> <span class="keyword">new</span></span><br><span class="line">                NotSupportedException(<span class="string">"未支持此编号产品生产。"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>对于程序调用者而言，它只需要知道通过工厂的 <code>createProduct</code>方法，指定产品编号—— <code>productNo</code> 可以得到对应的产品，而产品满足接口 <code>IProduct</code> 的规范，所以初始化就简单了许多。对于产品对象的创建，可以把一些特有产品规则写入工厂类中。</p>
<h4 id="抽象工厂（-Abstract-Factory）模式"><a href="#抽象工厂（-Abstract-Factory）模式" class="headerlink" title="抽象工厂（ Abstract Factory）模式"></a>抽象工厂（ Abstract Factory）模式</h4><p>抽象工厂模式可以向客户端提供一个接口，使得客户端在不必指定产品的具体情况下，创建多个产品族中的产品对象。</p>
<p>对于普通工厂而言，它解决了一类对象创建问题，但是有时候对象很复杂，有几十种，又分为几个类别。如果只有一个工厂，面对如此多的产品，这个工厂需要实现的逻辑就太复杂了，所以我们希望把工厂分成好几个，这样便于工厂产品规则的维护。但是设计者并不想让调用者知道具体的工厂规则，而只是希望他们知道有一个统一的工厂即可。这样的设计有助于对外封装和简化调用者的使用，毕竟调用者可不想知道选择具体工厂的规则。</p>
<p>仍以车厂为例，生产商不会把轿车、大巴车、警车、吉普车、救护车等车型都放在个车厂生产，那样会造成车厂异常复杂，从而导致难以管理和维护。所以，生产商通常会把它们按种类分为轿车厂、大巴车厂、警车厂、吉普车厂等分厂，每个种类下面有一些型号的产品。但是对于客户而言，只要告诉客服自己需要什么类型的车即可，至于如何分配给工厂那是客服的事情。</p>
<p>客户只是认为有一个能够生产各类车的工厂，它能生成我所需要的产品，这里工厂只是一个虚拟的概念，并不真实存在，它是通过车厂内部各个分厂去实现的，这个虚拟工厂被称为抽象工厂，它的各个分厂称为具体工厂。为了统一，需要制定一个接口规范（ IProductFactory），所有的具体工厂和抽象工厂都要实现这个接口， IProductFactory工厂接口就可以设计成：</p>
<h3 id="单例模式"><a href="#单例模式" class="headerlink" title="单例模式"></a>单例模式</h3><h3 id="原型模式"><a href="#原型模式" class="headerlink" title="原型模式"></a>原型模式</h3><h3 id="代理模式"><a href="#代理模式" class="headerlink" title="代理模式"></a>代理模式</h3><h3 id="委派模式"><a href="#委派模式" class="headerlink" title="委派模式"></a>委派模式</h3><h3 id="策略模式"><a href="#策略模式" class="headerlink" title="策略模式"></a>策略模式</h3><h3 id="模板模式"><a href="#模板模式" class="headerlink" title="模板模式"></a>模板模式</h3><h3 id="适配器模式"><a href="#适配器模式" class="headerlink" title="适配器模式"></a>适配器模式</h3><h3 id="装饰者模式"><a href="#装饰者模式" class="headerlink" title="装饰者模式"></a>装饰者模式</h3><h3 id="观察者模式"><a href="#观察者模式" class="headerlink" title="观察者模式"></a>观察者模式</h3><h3 id="各种设计模式的总结与对比"><a href="#各种设计模式的总结与对比" class="headerlink" title="各种设计模式的总结与对比"></a>各种设计模式的总结与对比</h3><h4 id="Spring中常用的设计模式-1"><a href="#Spring中常用的设计模式-1" class="headerlink" title="Spring中常用的设计模式"></a>Spring中常用的设计模式</h4><table>
<thead>
<tr>
<th>设计模式</th>
<th>归纳</th>
<th>举例</th>
</tr>
</thead>
<tbody><tr>
<td>工厂模式</td>
<td>只对结果负责，封装创建过程</td>
<td><code>BeanFactory</code>、<code>Calender</code></td>
</tr>
<tr>
<td>单例模式</td>
<td>保障独一无二</td>
<td><code>ApplicationContext</code>、<code>Calender</code></td>
</tr>
<tr>
<td>原型模式</td>
<td>把一根毛，吹出千万个猴子</td>
<td><code>ArrayList</code>、<code>PrototypeBean</code></td>
</tr>
<tr>
<td>代理模式</td>
<td>找人办事，增强职责</td>
<td><code>ProxyFactoryBean</code>、<code>jdkDynamicAopProxy</code>、<code>CglibAopProxy</code></td>
</tr>
<tr>
<td>委派模式</td>
<td>干活算你的，功劳算我的</td>
<td><code>DispatcherServlet</code>、<code>BeanDefinitionParserDelegate</code></td>
</tr>
<tr>
<td>策略模式</td>
<td>用户选择，结果统一</td>
<td><code>InstantiationStrategy</code></td>
</tr>
<tr>
<td>模板模式</td>
<td>流程标准化，自己实现定制</td>
<td><code>jdbcTemplate</code>、<code>HttpServlet</code></td>
</tr>
<tr>
<td>适配器模式</td>
<td>兼容转换头</td>
<td><code>AdvisorAdapter</code>、<code>HanderAdapter</code></td>
</tr>
<tr>
<td>装饰器模式</td>
<td>包装，同宗同源</td>
<td><code>BufferedReader</code>、<code>InputStream</code>、<code>OutputStream</code></td>
</tr>
<tr>
<td>观察者模式</td>
<td>在任务完成时通知</td>
<td><code>ContextLoaderListener</code></td>
</tr>
</tbody></table>
<h4 id="Spring中的编程思想总结"><a href="#Spring中的编程思想总结" class="headerlink" title="Spring中的编程思想总结"></a>Spring中的编程思想总结</h4><table>
<thead>
<tr>
<th>Spring思想</th>
<th>应用场景</th>
<th>归纳</th>
</tr>
</thead>
<tbody><tr>
<td>OOP（面向对象编程）</td>
<td>用程序归纳总结生活中的一切事物</td>
<td>封装、继承、多态</td>
</tr>
<tr>
<td>BOP（面向Bean编程）</td>
<td>面向Bean（普通Java类）设计程序，解放程序员</td>
<td>一切从Bean开始</td>
</tr>
<tr>
<td>AOP(面向切面编程)</td>
<td>找出多个类中有一定规律的代码，开发时拆开，运行时再合并</td>
<td>解耦，专人做专事</td>
</tr>
<tr>
<td>IoC（控制反转）</td>
<td>将new对象的动作交给Spring管理，并由Spring保存已创建的对象（IoC容器）</td>
<td>转交控制权</td>
</tr>
<tr>
<td>DI/DL（依赖注入/依赖查找）</td>
<td>Spring不仅保存自己创建的对象，而且保存对象与对象之间的关系。注入即赋值，主要有三种方式：构造方法、set方法、直接赋值</td>
<td>赋值</td>
</tr>
</tbody></table>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\07\10\Spring\SpringMVC\" rel="bookmark">Spring MVC</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\08\08\Java\Java-03-类型系统\" rel="bookmark">Java类型系统</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\03\23\Java\Java书单\" rel="bookmark">计算机书单</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\03\21\Java\Java处理常见的数据格式\" rel="bookmark">Java常用类</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\04\06\Java\Java多线程\" rel="bookmark">Java多线程</a></div>
    </li>
  </ul>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/tags/Spring/" rel="tag"><i class="fa fa-tag"></i> Spring</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/10/Spring/SpringMVC/" rel="prev" title="Spring MVC">
      <i class="fa fa-chevron-left"></i> Spring MVC
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/31/408/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F/" rel="next" title="深入理解计算机系统">
      深入理解计算机系统 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#面向对象的七大设计原则"><span class="nav-number">1.</span> <span class="nav-text">面向对象的七大设计原则</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#开闭原则"><span class="nav-number">1.1.</span> <span class="nav-text">开闭原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#依赖倒置原则"><span class="nav-number">1.2.</span> <span class="nav-text">依赖倒置原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#单一职责原则"><span class="nav-number">1.3.</span> <span class="nav-text">单一职责原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#接口隔离原则"><span class="nav-number">1.4.</span> <span class="nav-text">接口隔离原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#迪米特原则"><span class="nav-number">1.5.</span> <span class="nav-text">迪米特原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#里氏替换原则"><span class="nav-number">1.6.</span> <span class="nav-text">里氏替换原则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#合成复用原则"><span class="nav-number">1.7.</span> <span class="nav-text">合成复用原则</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Spring中常用的设计模式"><span class="nav-number">2.</span> <span class="nav-text">Spring中常用的设计模式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#工厂模式"><span class="nav-number">2.1.</span> <span class="nav-text">工厂模式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#普通工厂（Simple-Factory）模式"><span class="nav-number">2.1.1.</span> <span class="nav-text">普通工厂（Simple Factory）模式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#抽象工厂（-Abstract-Factory）模式"><span class="nav-number">2.1.2.</span> <span class="nav-text">抽象工厂（ Abstract Factory）模式</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#单例模式"><span class="nav-number">2.2.</span> <span class="nav-text">单例模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#原型模式"><span class="nav-number">2.3.</span> <span class="nav-text">原型模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代理模式"><span class="nav-number">2.4.</span> <span class="nav-text">代理模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#委派模式"><span class="nav-number">2.5.</span> <span class="nav-text">委派模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#策略模式"><span class="nav-number">2.6.</span> <span class="nav-text">策略模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模板模式"><span class="nav-number">2.7.</span> <span class="nav-text">模板模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#适配器模式"><span class="nav-number">2.8.</span> <span class="nav-text">适配器模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#装饰者模式"><span class="nav-number">2.9.</span> <span class="nav-text">装饰者模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#观察者模式"><span class="nav-number">2.10.</span> <span class="nav-text">观察者模式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#各种设计模式的总结与对比"><span class="nav-number">2.11.</span> <span class="nav-text">各种设计模式的总结与对比</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Spring中常用的设计模式-1"><span class="nav-number">2.11.1.</span> <span class="nav-text">Spring中常用的设计模式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Spring中的编程思想总结"><span class="nav-number">2.11.2.</span> <span class="nav-text">Spring中的编程思想总结</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Lanqilu"
      src="http://img.whl123456.top/image/avatar.jpg">
  <p class="site-author-name" itemprop="name">Lanqilu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">85</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">39</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/lanqilu" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lanqilu" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=zqKvoL_noruOqKG2o6_nouCtoaM" title="E-Mail → http:&#x2F;&#x2F;mail.qq.com&#x2F;cgi-bin&#x2F;qm_share?t&#x3D;qm_mailme&amp;email&#x3D;zqKvoL_noruOqKG2o6_nouCtoaM" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i></a>
      </span>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lanqilu</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  

  

    </div>
</body>
</html>
